package com.example.hotelsystem.utils;

import com.example.hotelsystem.entity.User;
import com.example.hotelsystem.service.UserService;
import com.example.hotelsystem.service.impl.UserServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
@Component
public class UserUtil {
    @Autowired
    private UserService userService;

    public static UserUtil userUtil;

    @PostConstruct
    public void init(){
        userUtil=this;   //必需
        userUtil.userService=this.userService;
    }

    public static User getUser(){
        User user  = (User) SecurityUtils.getSubject().getPrincipal();
        if(user==null){
            return null;
        }
        User flash = userUtil.userService.selectById(user.getId());
        return flash;
    }

}
